package com.plian.system.controller.sys.seal;


import com.plian.Tools.FileTools;
import com.plian.system.annotation.LogOperation;
import com.plian.system.entity.sys.SealApply;
import com.plian.system.model.ListResult;
import com.plian.system.model.R;
import com.plian.system.mybatis.support.Query;
import com.plian.system.service.sys.seal.ISealApplyService;
import com.plian.system.vo.sys.SealApplyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用印申请 前端控制器
 * </p>
 *
 * @author husong
 * @since 2023-03-18 13:09:29
 */
@RestController
@RequestMapping("/api/sealApply")
@Api(tags = "用印申请")
@RequiredArgsConstructor
public class SealApplyController {

    private final ISealApplyService sealApplyService;

    @ApiOperation("查看记录")
    @PostMapping("/list")
    public ListResult<SealApplyVO> list(@RequestBody Query query) {
        return sealApplyService.findAll(query);
    }

    @ApiOperation("详情")
    @PostMapping("/detail")
    public R<SealApplyVO> detail(@RequestBody SealApply sealApply) {
        return R.data(sealApplyService.detail(sealApply));
    }

    @ApiOperation(value = "新增或修改")
    @PostMapping("/submit")
    @LogOperation("用印申请-提交")
    public R submit(@Validated @RequestBody SealApply sealApply) {
        return sealApplyService.saveOrUpdate(sealApply) ? R.data(sealApply): R.fail();
    }

    @ApiOperation(value = "保存签名和流程相关")
    @PostMapping("/signOrFlow")
    @LogOperation("用印申请-更新签名及流程")
    public R signOrFlow(@RequestBody SealApply sealApply) {
        return sealApplyService.updateSignOrFlow(sealApply) ? R.success() : R.fail();
    }

    @PostMapping("/detailPdf")
//    @PassToken
    @ApiOperation(value = "详情pdf")
    public ResponseEntity<FileSystemResource> detailPdf(@RequestBody SealApply sealApply) {
        return FileTools.exportPdf(sealApplyService.detailPdf(sealApply));
    }
}

